#include <iostream>
#include <string>
#include <unordered_set>
using namespace std;

class Solution {
public:
    int lengthOfLongestSubstring(string s)
    {
        if(s.size() == 0)
            return 0;
        unordered_set<char> lookup;
        int maxStr = 0;
        int left = 0;
        for(int i = 0; i < s.size(); i++)
        {
            while (lookup.find(s[i]) != lookup.end())
            {
                // 如果字符串中存在字符，删除左侧的字符
                lookup.erase(s[left]);
                left ++;
            }
            maxStr = max(maxStr,i-left+1);
            lookup.insert(s[i]);
        }
        return maxStr;       
    }
};

int main()
{
    int lens;
    string s = "kkoukouzhhsgjs";
    Solution kk;
    lens = kk.lengthOfLongestSubstring(s);
    cout << "lens is :" << lens << endl;
    return 0;
}